#ifndef __POOL_H__
#define __POOL_H__

#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>

#include <errno.h>
#include <pthread.h>

#define MAX_TIDS    20
#define MAX_WAITING 100

struct task
{
    void *(*task)(void *);          //需要执行的函数
    void *arg;                      //参数
    struct task *next;              //单向链表
};

typedef struct thread_pool
{
    pthread_mutex_t lock;           //互斥锁
    pthread_cond_t  cond;           //条件量

    bool shutdown;                  //线程池销毁标记
    struct task *task_list;         //任务链队列指针
    pthread_t *tids;                //线程ID

    unsigned  waiting_tasks;        //等待的任务个数
    unsigned  max_waiting_tasks;    //最大等待的任务个数
    unsigned  active_threads;       //活跃线程个数
}thread_pool;

bool init_pool(thread_pool *pool, unsigned int threads_number);             //初始化线程池
bool add_task(thread_pool *pool, void *(*mytask)(void *arg), void *arg);    //添加任务

void *routine(void *arg);//线程函数

#endif